package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.pojo.PetPhoto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.mapstruct.Mapper;

import java.util.List;

/**
 * @author LeXin Huang
 * @date 2021年04月21日 22:59
 */
@Mapper
public interface PetPhotoMapper extends BaseMapper<PetPhoto> {

    /**
     * 根据宠物 id 查询宠物图片url 数组
     * @param petId 宠物id
     * @return 宠物图片数组(如果存在), 否则为 null
     */
    @Results(id = "petPhotoMap", value = {
            @Result(column = "id", property = "id", id = true),
            @Result(column = "pet_photo_url", property = "photoUrl"),
            @Result(column = "pet_id", property = "petId"),
    })
    @Select("Select * from pet_photo where pet_id = #{pet_id}")
    List<PetPhoto> selectByPetId(@Param("pet_id") Integer petId);
}
